package com.stylefeng.guns.core.util;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.modular.system.model.Dict;
import com.stylefeng.guns.modular.system.service.IDictService;

public class SysDictUtils {
	
	public void getValue(String key, String name, String defaultValue){
		
	}
	
	/**
	 * 根据key拿字典的值 如果不存在则以默认值创建
	 * @param key
	 * @param defaultValue
	 */
	public String getValue(String key, String defaultValue){
		IDictService dictService = SpringContextHolder.getBean(IDictService.class);
		Dict dict = dictService.selectOne(new EntityWrapper<Dict>().eq("code", key));
		if(null != dict){
			return dict.getName();
		}else{
			dict = new Dict(key, defaultValue);
			dictService.insert(dict);
			return defaultValue;
		}
	}
}
